# -*- coding: utf-8 -*-
import os

import wx
import wx.xrc

from core.file import File


class DeleteFileDialog(wx.Dialog):

    def __init__(self, parent, file:File, root_file:File):
        wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition,
                           size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE)
        self.file = file
        self.root_file = root_file
        self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)

        bSizer9 = wx.BoxSizer(wx.VERTICAL)
        msg = f"确定要删除文件【{file.relative_path}】吗？"
        self.m_staticText4 = wx.StaticText(self, wx.ID_ANY, msg, wx.DefaultPosition, wx.DefaultSize,
                                           wx.ALIGN_CENTER_HORIZONTAL)
        self.m_staticText4.Wrap(-1)

        self.m_staticText4.SetFont(
            wx.Font(wx.NORMAL_FONT.GetPointSize(), wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD,
                    False, wx.EmptyString))

        bSizer9.Add(self.m_staticText4, 0, wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, 5)
        self.button_submit = wx.Button(self, wx.ID_ANY, u"确定", wx.DefaultPosition, wx.DefaultSize, 0)
        self.button_cancel = wx.Button(self, wx.ID_ANY, u"取消", wx.DefaultPosition, wx.DefaultSize, 0)
        bSizer_button = wx.BoxSizer(wx.HORIZONTAL)
        bSizer_button.Add(self.button_submit, 0, wx.ALIGN_CENTER|wx.ALL, 5)
        bSizer_button.Add(self.button_cancel, 0, wx.ALIGN_CENTER|wx.ALL, 5)

        bSizer9.Add(bSizer_button, 0, wx.ALIGN_CENTER | wx.ALL, 5)

        self.SetSizer(bSizer9)
        self.Layout()
        bSizer9.Fit(self)

        self.Centre(wx.BOTH)

        # Connect Events
        self.button_submit.Bind(wx.EVT_BUTTON, self.button_click_submit)
        self.button_cancel.Bind(wx.EVT_BUTTON, self.button_click_cancel)

    def __del__(self):
        pass

    def button_click_cancel(self, event):
        self.Close()

    def button_click_submit(self, event):
        if self.file is not None:
            self.file.delete()
            self.Parent.refresh(self.root_file, type="tree")
        self.Close()
